package com.yuanjing.xiangqinxiangai

import android.os.Bundle
import com.yuanjing.xiangqinxiangai.plugin.FaceRecognitionPlugin
import com.yuanjing.xiangqinxiangai.plugin.LiveMessagePlugin
import com.yuanjing.xiangqinxiangai.view.LivePreviewViewFactory
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.platform.PlatformViewRegistry
import io.flutter.plugins.GeneratedPluginRegistrant

var liveMessagePlugin: LiveMessagePlugin? = null

class MainActivity : FlutterActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // 注册 LiveMessagePlugin
        liveMessagePlugin = LiveMessagePlugin(flutterEngine!!.dartExecutor)

        // 注册 LivePreviewViewFactory
        val messenger: BinaryMessenger = flutterEngine!!.dartExecutor
        val registry: PlatformViewRegistry = flutterEngine!!.platformViewsController.registry
        registry.registerViewFactory(
            "plugins.flutter.io/live_preview_view",
            LivePreviewViewFactory(messenger)
        )
        // 注册其他插件（如果有的话）
//        GeneratedPluginRegistrant.registerWith(flutterEngine!!)

    }

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        getFlutterEngine()?.dartExecutor?.let {
            FaceRecognitionPlugin(this, it)
        }
    }
}